use strict;
use vars qw($VERSION %IRSSI);

use Irssi 20011014;

$VERSION = "0.1";
%IRSSI = (
	authors     => "Rafal Skoczylas",
	contact     => "nils\@secprog.org",
	name        => "trim",
	licence     => "GPL",
	description => "trims spaces from the begging and the end of each written line before sending",
);

sub trim($)
{
   my $x = shift ;
   $x =~ s/^\s+// ;
   $x =~ s/\s+$// ;
   return $x ;
}

sub sig_command_msg
{
	my ($cmd, $server, $winitem) = @_;
	my ($param, $target,$data) = $cmd =~ /^(-\S*\s)?(\S*)\s(.*)/;

   if ($data =~ /\s+$/) {
      $data = trim($data);
      Irssi::signal_emit("command msg", "$target $data", $server, $winitem);
      Irssi::signal_stop();
   }
}

Irssi::command_bind('msg', 'sig_command_msg');
